﻿<html>
    <head>
        <title>Блог</title>
        <link rel='stylesheet' type='text/css' href='main.css'> 
        <script type="text/javascript" src="jquery-1.8.1.js"></script>
        <script>
            function addKarma(userID, karma) {
                $.ajax({  
                    type: "POST",  
                    url: "index.php?controller=Karma",  
                    data: "userID="+userID+"&karma="+karma,  
                    success: function(html){  
                    $(".u"+userID).html(html);  
                    }  
                });  
            }
        </script>
    </head>
    
    <body>
        <div class='hat'><a href='index.php'>Блог</a>
        </div>
        
        <div class='auth'>
        Здравствуй, <?=$this->user->fName.' '.$this->user->lName?>!<br><br>
        
        <? if ( $this->user->id == false ) {?>
            <form action='index.php?controller=auth' method='post'>
                <input type='text' size='10' name='userName'>
                <input type='password' size='10' name='password'>
                <input type='submit' value='login'>
                &nbsp <a href='index.php?controller=reg'>[Регистрация]</a>
            </form>
        <? } else {?>
        <a href='index.php?controller=write'>Новая статья</a>
        &nbsp | &nbsp
        <a href='index.php?controller=index&logout=1'>Выйти</a>
        <? if ( $this->user->userName == 'admin' ) {?>
        &nbsp | &nbsp
        <a href='index.php?controller=admin'>Авторы</a>
        <?}?>
        <br><br>
        <? } ?>
        </div>
        <div class='articles'>
            <div class='art'>
                <div class='art_subj'><?=$this->article->subject?></div>
            
                <?if ($this->article->tags[0]) {?>
                <div class='art_tags'>[
                <? for ($it=0; $it<sizeof($this->article->tags); $it++) {?>
                <a href='index.php?tag=<?=$this->article->tags[$it]?>'><?=$this->article->tags[$it]?></a>
                <?if (isset($this->article->tags[$it+1])){?>,<?}?>
                <?}?>
                ]</div>
                <?}?>
                    
                <div class='art_text'><?=$this->article->text?></div>
                
                <div class='karmaBlock'>
                    <div class='plus_karma'><a onclick='addKarma(<?=$this->article->userID?>,<?=$this->article->karma?>)'>+</a></div>
                    <div class='karma'><div class='u<?=$this->article->userID?>'><?=$this->article->karma?></div></div>
                </div>
            
                <div class='art_info'>
                    <?=$this->article->time?> <b>by</b> 
                    <a href='index.php?authorID=<?=$this->article->userID?>'><?=$this->article->userFullName?></a>
                </div>
           
                <? if ( $this->article->userID == $this->user->id ) {?>
                <div class='art_ed'><a href='index.php?controller=edit&artID=<?=$this->article->id?>'>Редактировать</a> | 
                 <a href='index.php?controller=index&del=1&artID=<?=$this->article->id?>'>Удалить</a></div>
                <? } ?>
            </div>
            <div class='form_comments'>
            <form action='index.php?controller=comment' method='post'>
                <input type='hidden' name='artID' value='<?=$this->article->id?>'>
                <textarea name='text' cols='50'></textarea><br>
                <input type='submit' name='newCom' value='Комментировать'>
            </form>
            </div>
        </div>
        
        
        <div class='comments'>
        <? foreach($this->comments as $comment){?>
            <div class='comment'>
            <div class='com_author_name'><?=$comment->userFullName?></div>
            <div class='com_text'><?=$comment->text?></div>
            <div class='com_time'><?=$comment->time?></div>
            </div>
        <?}?>
        </div>
    </body>
</html>